<template>
  <div style="background-color: #f7f7f7; height: 100%">
    <!-- 头部 -->
    <div class="header-content">
      <div class="header-image">
        <img src="../../assets/img/myProfile/logo2.png" alt="" />
      </div>
      <div class="user-info" @click="ifNotLogin">
        <div>{{ loginUserId ? name111 : '登录/注册' }}</div>
        <div>{{ loginUserId && phone111 }}</div>
      </div>
      <div v-show="type == 'person' || type == 'expert'" class="setter-icon" @click="setInfo"></div>
    </div>

    <!-- 选项 专家 -->
    <div v-if="type == 'expert'" class="select-content-other">
      <div>
        <div class="select-item" @click="toToMyquest">
          <div>
            <img src="../../assets/img/myProfile/myZIXUN.png" alt="" />
          </div>
          <div>我的咨询</div>
        </div>
        <div class="select-item" @click="goToMyResponse">
          <div>
            <img src="../../assets/img/myProfile/myHUIFU.png" alt="" />
          </div>
          <div>我的回复</div>
        </div>
        <div class="select-item" @click="myShouCang">
          <div>
            <img src="../../assets/img/myProfile/mySHOUCANG.png" alt="" />
          </div>
          <div>我的收藏</div>
        </div>
        <div class="select-item" @click="personManage">
          <div>
            <img src="../../assets/img/myProfile/myRENCAI.png" alt="" />
          </div>
          <div class="tt">人才供需</div>
        </div>
      </div>
      <div>
        <div class="select-item" @click="shareManage">
          <div>
            <img src="../../assets/img/myProfile/myGONGXIANG.png" alt="" />
          </div>
          <div class="tt">共享管理</div>
        </div>
      </div>
    </div>
    <!-- 其他 -->
    <div v-else class="select-content-other">
      <div>
        <div class="select-item" @click="toToMyquest">
          <div>
            <img src="../../assets/img/myProfile/myZIXUN.png" alt="" />
          </div>
          <div>我的咨询</div>
        </div>

        <div class="select-item" @click="myShouCang">
          <div>
            <img src="../../assets/img/myProfile/mySHOUCANG.png" alt="" />
          </div>
          <div>我的收藏</div>
        </div>

        <div class="select-item" @click="personManage">
          <div>
            <img src="../../assets/img/myProfile/myRENCAI.png" alt="" />
          </div>
          <div class="tt">人才供需</div>
        </div>

        <div class="select-item" @click="shareManage">
          <div>
            <img src="../../assets/img/myProfile/myGONGXIANG.png" alt="" />
          </div>
          <div class="tt">共享管理</div>
        </div>
      </div>
    </div>

    <!-- 跳转 -->
    <div style="margin-top: 10px">
      <van-cell size="large" is-link @click="updatePhone">
        <template #title>
          <img
            style="width: 19px; height: 19px; position: relative; top: 4px"
            src="../../assets/img/myProfile/phoneXIUGAI.png"
            alt=""
          />
          <span class="custom-title">修改手机号</span>
        </template>
      </van-cell>
      <van-cell size="large" is-link @click="updatePassword">
        <template #title>
          <img
            style="width: 19px; height: 19px; position: relative; top: 4px"
            src="../../assets/img/myProfile/passwordXIUGAI.png"
            alt=""
          />
          <span class="custom-title">修改密码</span>
        </template>
      </van-cell>
      <!-- <van-cell size="large"  is-link @click="about">
      <template #title>
        <img style="width: 19px;height: 19px;position: relative;top: 4px;" src="../../assets/img/myProfile/aboutUS.png" alt="">
        <span class="custom-title">关于我们</span>
      </template>
    </van-cell> -->
      <van-cell size="large" is-link @click="jiance">
        <template #title>
          <img
            style="width: 19px; height: 19px; position: relative; top: 4px"
            src="../../assets/img/myProfile/jianceGENGXIN.png"
            alt=""
          />
          <span class="custom-title">检测更新</span>
        </template>
      </van-cell>
    </div>

    <!-- 退出登录 -->
    <div v-if="loginUserId" class="logout" @click="logout">退出登录</div>
  </div>
</template>

<script>
import { Cell, CellGroup, Toast, Dialog } from 'vant'
import { getValue, setValue, setObject, clear } from '@/utils/auth'
import { postHandle, getHandle } from '@/api'
import { imgPaths } from '@/filters'
export default {
  name: '',
  data() {
    return {
      detailData: {},
      type: getValue('roleCode'),
      loginUserId: getValue('loginUserId'),
      name111: getValue('loginName'),
      phone111: getValue('mobilePhone')
    }
  },
  created() {
    this.$bridge.register('refresh', data => {
      this.type = getValue('roleCode')
      this.loginUserId = getValue('loginUserId')
      this.name111 = getValue('loginName')
      this.phone111 = getValue('mobilePhone')
    })

    // 专家信息详情
    this.getDetailData()
  },
  methods: {
    // 如果没有登录/点击跳转登录
    ifNotLogin() {
      if (this.loginUserId) return
      this.$bridge.call('registerAndLogin')
    },
    // 我的收藏
    myShouCang() {
      this.$bridge.call('myShouCang')
    },
    // 我的评价
    activeManage() {
      this.$bridge.call('activeManage')
    },
    // 良种羊
    sheepGX() {
      this.$bridge.call('sheepGX')
    },
    // 人才供需/人才管理
    personManage() {
      this.$bridge.call('personManage')
    },
    // 共享管理
    shareManage() {
      this.$bridge.call('shareManage')
    },
    // 修改手机号
    updatePhone() {
      this.$bridge.call('changePhone')
    },
    // 关于
    about() {
      this.$bridge.call('about')
    },
    // 检测更新
    jiance() {
      this.$bridge.call('jiance')
    },
    // 修改密码
    updatePassword() {
      this.$bridge.call('forgetPassword')
    },
    // 退出登录
    logout() {
      Dialog.confirm({
        title: '提示',
        message: '您确定要退出登录吗?',
        confirmButtonColor: 'black'
      })
        .then(() => {
          localStorage.removeItem('lxnsy-loginName')
          localStorage.removeItem('lxnsy-mobilePhone')
          localStorage.removeItem('lxnsy-loginUserId')
          localStorage.removeItem('lxnsy-roleCode')
          localStorage.removeItem('lxnsy-userType')
          localStorage.removeItem('lxnsy-token')
          localStorage.removeItem('lxnsy-userAccId')
          localStorage.removeItem('lxnsy-subjectInfoId')
          localStorage.removeItem('lxnsy-tenantCode')
          localStorage.removeItem('lxnsy-tenantName')
          localStorage.removeItem('lxnsy-auditStatus')
          localStorage.removeItem('lxnsy-name')
          if (!getValue('loginUserId')) {
            this.$bridge.call('outLogin')
          }
        })
        .catch(() => {
          // on cancel
        })

      // setTimeout(() => {
      //   this.$bridge.call('outLogin')
      // }, '1000')
    },
    // 跳转我的咨询
    toToMyquest() {
      this.$bridge.call('myAdvice')
    },
    // 我的回复
    goToMyResponse() {
      this.$bridge.call('myRresponse')
    },
    // 设置档案信息
    setInfo() {
      if (this.type == 'person') {
        this.$bridge.call('myProfile_common')
      } else if (this.type == 'expert') {
        this.$bridge.call('myProfile_expert')
      } else {
        return
      }
    },
    // 当前用户的详细信息(专家)
    getDetailData() {
      if (this.type == 0) {
        getHandle(`/agri/api/common/tenant/queryDetail4Person/${getValue('loginUserId')}`).then(res => {
          this.detailData = res.data
        })
      } else if (this.type == 1) {
        getHandle('/agri/api/common/subjectInfoExpert/queryDetailByUserId', {
          userId: getValue('loginUserId')
        }).then(res => {
          this.detailData = res.data
        })
      }
    }
  },
  components: {
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup
  }
}
</script>

<style lang="scss" scoped>
.header-content {
  width: 100%;
  height: 110px;
  position: relative;
  background: url(../../assets/img/myProfile/headerBg.png);
  background-size: 100% 100%;
  display: flex;
  align-items: center;
  .header-image {
    width: 56px;
    height: 56px;
    margin-left: 20px;
    margin-right: 20px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .user-info {
    width: 145px;
    height: 56px;
    padding-top: 5px;
    div {
      font-size: 17px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #ffffff;
      line-height: 24px;
    }
    & > div:nth-child(2) {
      font-size: 15px;
    }
  }
  .setter-icon {
    width: 20px;
    height: 20px;
    background: url(../../assets/img/myProfile/set-icon.png);
    background-size: 100% 100%;
    position: absolute;
    right: 20px;
    top: 33px;
  }
}
.select-content {
  width: 375px;
  height: 165px;
  margin-top: 10px;
  background-color: #fff;
  & > div {
    width: 100%;
    height: 50%;
    display: flex;
  }
  & > div:first-child {
    justify-content: space-around;
  }
  & > div:nth-child(2) {
    & > div {
      margin: 0 19px;
    }
  }
  .select-item {
    width: 56px;
    height: 75px;
  }
}

.select-content-other {
  width: 375px;
  height: 85px;
  margin-top: 10px;
  background-color: #fff;
  & > div {
    width: 100%;
    height: 50%;
    display: flex;
  }
  & > div:first-child {
    justify-content: space-around;
  }
  & > div:nth-child(2) {
    & > div {
      margin: 0 19px;
    }
  }
  .select-item {
    width: 56px;
    height: 75px;
  }
}

.select-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  & div:first-child {
    width: 34px;
    height: 34px;
    margin: 15px 0 6px 0;
    img {
      width: 100%;
      height: 100%;
    }
  }
  & div:nth-child(2) {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    line-height: 20px;
    white-space: nowrap;
  }
}
.custom-title {
  font-size: 15px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
}

.logout {
  width: 100%;
  height: 49px;
  margin-top: 40px;
  background-color: #fff;
  line-height: 49px;
  text-align: center;
  color: rgba(55, 181, 181, 1);
  font-size: 17px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #37b5b5;
}

.van-cell--large {
  padding-top: 17px;
  padding-bottom: 17px;
}
</style>
